package com.taoyige.ui;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.content.Context;

import com.taoyige.AppConfig;
import com.taoyige.common.APPUpdateUtil;
import com.taoyige.AppContext;
import com.taoyige.AppException;
import com.taoyige.R;
import com.taoyige.bean.Order;
import com.taoyige.bean.User;
import com.taoyige.common.UIHelper;
import com.taoyige.widget.BadgeView;
import com.taoyige.widget.LoadingDialog;

/**
 * 关于淘一个
 * @author 刘宁
 *
 */
public class AboutTaoyigeActivity extends BaseActivity {
	private TextView userHeadText;
	private TextView appVersion;
	private ImageButton returnBack,homePage;
	private RelativeLayout checkUpdate,flushImage;
	private AppContext appContext;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.about_taoyige);
		appContext = (AppContext) getApplication();
		initView();
	}	
	
	private void initView(){
		appVersion = (TextView)findViewById(R.id.app_version);
		returnBack=(ImageButton)findViewById(R.id.user_hear_return_back);
		homePage=(ImageButton)findViewById(R.id.user_hear_homePage);
		checkUpdate=(RelativeLayout)findViewById(R.id.check_update);
		flushImage=(RelativeLayout)findViewById(R.id.flush_image);
		
		checkUpdate.setOnClickListener(updateListener);
		flushImage.setOnClickListener(flushListener);
		returnBack.setOnClickListener(userCenterListener);
		homePage.setOnClickListener(homeListener);		
		userHeadText=(TextView)findViewById(R.id.user_hear_text);
		userHeadText.setText("关于淘一个");
		setCurrentVersion();

	}	
	
	/**
	 * 获取当前客户端版本信息
	 */
	private void setCurrentVersion(){		
        try {         	
        	PackageInfo info = getApplicationContext().getPackageManager().getPackageInfo(this.getPackageName(), 0);
        	String curVersionName = info.versionName;
        	int curVersionCode = info.versionCode;
        	appVersion.setText("淘一个 V"+curVersionName+"."+curVersionCode);
        } catch (NameNotFoundException e) {    
			e.printStackTrace(System.err);
		} 
	}
	/**
	 * 检查版本更新
	 */
	private View.OnClickListener updateListener = new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			APPUpdateUtil.getUpdateManager().checkAppUpdate(v.getContext(), true);
		}
	};
	/**
	 * 清空图片缓存
	 */
	private View.OnClickListener flushListener = new View.OnClickListener() {		
		@Override
		public void onClick(View v) {
			appContext.clearAppCache();		
			UIHelper.ToastMessage(v.getContext(), "缓存已清空");
		}
	};
	private View.OnClickListener homeListener = new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			UIHelper.showHomePage(v.getContext());
		}
	};
	
	private View.OnClickListener userCenterListener = new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			UIHelper.showUser(v.getContext());
		}
	};
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		return false;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
